<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网页浏览进度条</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #container{
            background-color: lightcoral;
            height: 5000px;
        }
        #progress{
            height: 2px;
            background:#369;
            position: fixed;
            top: 0;
            left: 0;
            width: 0%;
        }
    </style>
</head>
<body>
    <div id="progress"></div>
    <div id="container">

    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <script>
        //container容器的中高度
        let allHeight = $('#container').innerHeight()
        //屏幕的高度
        let winHeight = $(window).innerHeight()
        //算出可滚动的最大高度
        let scrollHeight = allHeight - winHeight
        //窗体的滚动条滚动事件
        $(window).scroll(function(){
            //获取每次滚动的高度
            let top = $(this).scrollTop()
            //算出滚动的占比
            let percent = top / scrollHeight * 100 + '%'
            //将该占比，赋值给progress
            $('#progress').css({
                width:percent
            })
        })
    </script>
</body>
</html>